home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 April / EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso / internet / others / removenewsgrp.lha / RemoveNewsGroup / RemoveNewsGroup.rexx < prev   
OS/2 REXX Batch file  |  1995-09-01  |  3KB  |  124 lines

  1. /* RemoveNewsGroup - v1.0 - 31-Aug-95 - by Jim McKinney */
  2.  
  3. /* An ARexx program that will totally remove a newsgroup from your system.
  4. First it removes the postings in a newsgroup and deletes its directories. 
  5. It then updates your Active files and .tinrc.  RemoveNewsGroup expects
  6. newsgroups to be found in the UUNews: directory.  Enjoy!  */
  7.  
  8. /* Open rexx.support library */
  9. lib = 'rexxsupport.library'
  10. if ~show('l', lib) then do
  11.   if ~addlib(lib, 0, -30, 0) then do
  12.     say 'Unable to open' lib
  13.     exit 10
  14.   end
  15. end
  16.  
  17. /* Check input */
  18. x = arg()
  19. if x == 0 | x > 1 then do
  20.   say 'USAGE: RemoveNewsGroup <news.group.name>'
  21.   exit 10
  22. end
  23.  
  24. /* Slice and dice newsgroup name */
  25. groupname = arg(1)
  26. say 'Removing "' || groupname || '" posts and directory structure.'
  27. start = 1 ; stop = length(groupname) ; x = 1
  28. do while start < stop
  29.   i = pos('.', groupname, start)
  30.   if i == 0 then i = stop + 1
  31.   name = 'name' || x || ' = substr(groupname, start, i - start)'
  32.   interpret name
  33.   start = i + 1 ; x = x + 1
  34. end
  35. x = x - 1
  36.  
  37. /* Build path string */
  38. pathname = ''
  39. do i = 1 for x
  40.   name = 'pathname = pathname || name' || i || '|| "/"'
  41.   interpret name
  42. end
  43. pathname = pathname || #?
  44.  
  45. pragma('d','UUNews:') /* Get in the right directory */
  46.  
  47. /* Delete posts and empty directories */
  48. address command 'Delete >nil:' pathname
  49. i = lastpos('/', pathname)
  50. do while i > 0
  51.   pathname = left(pathname, i - 1)
  52.   i = lastpos('/', pathname)
  53.   list = showdir(pathname, 'd')
  54.   if list == '' then address command 'Delete' pathname
  55. end
  56.  
  57. /* Update "Active" file */
  58. fileName = 'UUNews:Active' ; inFile = 'ifile' ; outFile = 'ofile' ; tempFile = 't:RNG-temp'
  59. call openFiles
  60. call readWrite
  61. call closeFiles
  62. call updateOld
  63.  
  64. /* Now let's fix "PurgeFile" */
  65. fileName = 'UUNews:PurgeFile'
  66. call openFiles
  67. call readWrite
  68. call closeFiles
  69. call updateOld
  70.  
  71. /* This last part is for tin. Remove it if you don't use tin. */
  72. /* Fix .newsrc. Assumes $HOME is AmiTCP: */
  73. fileName = 'AmiTCP:.newsrc'
  74. call openFiles
  75. call readWrite
  76. call closeFiles
  77. call updateOld
  78.  
  79. exit  /* All done!!! */
  80.  
  81.  
  82. /* My functions begin here */
  83.  
  84. /* Open files function */
  85. openFiles:
  86.   say 'Updating "' || fileName || '"'
  87.   if ~open(inFile, fileName, 'r') then do
  88.     say 'Error opening "' || fileName || '" file.'
  89.     exit 20
  90.   end
  91.   if ~open(outFile, tempFile, 'w') then do
  92.     say 'Error opening "' || tempFile || '" file.'
  93.     exit 20
  94.   end
  95. return
  96.  
  97. /* Read from input file and write output function */
  98. readWrite:
  99.   do forever
  100.     line = readln(inFile)
  101.     if eof(inFile) then leave
  102.     if ~abbrev(line, groupname) then writeln(outFile, line)
  103.   end
  104. return
  105.  
  106. /* Close files function */
  107. closeFiles:
  108.   if ~close(inFile) then do
  109.     say 'Error closing "' || fileName || '" file.'
  110.     exit 20
  111.   end
  112.   if ~close(outFile) then do
  113.     say 'Error closing "' || tempFile || '" file.'
  114.     exit 20
  115.   end
  116. return
  117.  
  118. /* Update files function.  Let AmigaDOS handle the file actions */
  119. updateOld:
  120.   address command "Delete >nil:" fileName
  121.   address command "Copy" tempFile fileName
  122.   address command "Delete >nil:" tempFile
  123. return
  124.